<?php
namespace app\index\service;
use think\Db;
use think\Cache;
use app\index\model\Specific;
use app\index\model\KnowUserLog;
use app\index\model\KnowUserVip;
use app\index\model\KnowUserType;
use app\index\model\KnowUserRecord;


class VipService
{
	public function disposeUserVip($userId = '')
	{
		if (!$userId) 
		{
			$user = user();
			
			$userId = $user['id'];
		}
		$data = KnowUserVip::getUserData([], $userId);

		$vips = [];

		foreach($data as $v)
		{
			$vips[$v['action']][$v['nav_id']] = ['type_id' => $v['type_id'],'is_ques' => $v['is_ques'],'expired_time' => $v['expired_time']];
		}

		return $vips;
	}


	public function getUserVip($param)
	{
		$vips = self::disposeUserVip();

		$status = 0;

		if ($vips)
		{
			if ( $vips[1])
			{
				$status = 1;
			}
			else
			{
				if ($vips[2][$param['id']])
				{
					if (!$vips[2][$param['id']]['type_id'])
					{
						$status = 1;
					}
					else
					{
						if (in_array($param['type_id'], explode(',', $vips[2][$param['id']]['type_id'])))
						{
							$status = 1;
						}
					}

					if ($status == 1 && $vips[2][$param['id']]['is_ques'] == 0) $status = 2;
				}
			}
		}
		// if(user()['id'] == '97caaf5ca038bd9be6b5443cbe046671')
		// {
		// 	echo $status;die;
		// }
		
		return $status;
	}
}